<template>
  <div class="app-container">
    <!-- 添加或修改发行管理对话框 -->
    <el-dialog :title="title" :visible.sync="visible" width="800px" v-if="visible" append-to-body
      :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" :label-width="labelWidth" :disabled="disabled">
        <el-form-item label="选择上架权益卡" prop="equityCardId">
          <el-select filterable :disabled="cardDisabled" v-model="form.equityCardId" placeholder="请选择" clearable
            size="small" :style="{width: inputWidth}">
            <el-option v-for="dict in cardOptin" :key="dict.cardId" :label="dict.cardName" :value="dict.cardId" />
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="" v-if="id">
          <img class="img_box" :src="form.cover" alt="">
          <div>¥{{form.price}}；{{form.issueTotal}}张</div>
        </el-form-item>
        <el-form-item label="发行方式" prop="issueType">
          <el-radio-group v-model="form.issueType" @change="radioChange">
            <el-radio :label="'1'">直接购买</el-radio>
            <!-- <el-radio :label="'2'">预约申购</el-radio> -->
            <el-radio :label="'3'">预约抢购</el-radio>
          </el-radio-group>
        </el-form-item>
        <!-- 直接购买 -->
        <div v-if="form.issueType=='1'">
          <el-form-item label="可购买时间" prop="date" ref="refOne" :key="1">
            <!-- <el-date-picker v-model="form.date1" type="datetime" placeholder="请选择" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" :clearable="false" :editable="false">
            </el-date-picker> -->
            <el-date-picker v-model="form.date" type="datetimerange" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              :clearable="false" @change="changeBuy" @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="发放库存" prop="issueInventory" ref="refTwo" :key="2">
            <el-input type="number" v-model.number="form.issueInventory" placeholder="请填写真实库存数量" :style="{width: inputWidth}" />
          </el-form-item>
          <el-form-item label="发放虚拟库存" prop="issueInventoryVirtual" ref="refTwo" :key="3">
            <el-input v-model="form.issueInventoryVirtual" placeholder="请填写虚拟库存数量" :style="{width: inputWidth}" />
          </el-form-item>
          <el-form-item label="每人限购" prop="issueLimit" ref="refThree" :key="4">
            <el-input v-model="form.issueLimit" placeholder="请填写每人限购数量" :style="{width: inputWidth}" />
          </el-form-item>
        </div>
        <!-- 预约申购 -->
        <div v-if="form.issueType=='2'">
          <el-form-item label="可预约时间" prop="dateTwo" ref="refOne" :key="5">
            <el-date-picker v-model="form.dateTwo" type="datetimerange" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              @change="activeChange" :clearable="false" @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="申购执行时间" prop="executeTime" ref="refTwo" :key="6">
            <el-date-picker v-model="form.executeTime" type="datetime" placeholder="请选择" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" :clearable="false" :editable="false" @blur="changeTime" @input="$forceUpdate()"
              :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="付款截止时间" prop="payTime" ref="refThree" :key="7">
            <el-date-picker v-model="form.payTime" type="datetime" placeholder="请选择" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" :clearable="false" :editable="false" @blur="changePayTime"
              @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="发放权益卡时间" prop="issueTime" ref="refFour" :key="8">
            <el-date-picker v-model="form.issueTime" type="datetime" placeholder="请选择" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" :clearable="false" :editable="false" @input="$forceUpdate()"
              :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="发放库存" prop="issueInventory" ref="refFive" :key="9">
            <el-input type="number" v-model.number="form.issueInventory" placeholder="请填写可售库存数量" :style="{width: inputWidth}" />
          </el-form-item>
        </div>
        <!-- 预约抢购 -->
        <div v-if="form.issueType=='3'">
          <el-form-item label="是否启用预约功能" prop="" ref="refSeven" :key="10">
            <el-switch v-model="form.subscribeEnable" :active-value="'1'" :inactive-value="'2'"></el-switch>
          </el-form-item>
          <el-form-item label="" prop="subscribeEnable" v-if="form.subscribeEnable=='1'" ref="refEight" :key="11">
            <el-radio-group v-model="form.subscribeType">
              <el-radio :label="'1'">预约用户直接进入白名单</el-radio>
              <el-radio :label="'2'">预约用户抽取白名单资格</el-radio>
              <el-radio :label="'3'">预约用户没有特权</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="公开发行预约时间" prop="dateThree" ref="refOne" v-if="form.subscribeEnable=='1'" :key="12">
            <el-date-picker v-model="form.dateThree" type="datetimerange" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              @change="dateThreeChange" :clearable="false" @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="白名单公布时间" prop="whiteTime" ref="refTwo" :key="13">
            <el-date-picker v-model="form.whiteTime" type="datetime" placeholder="请选择" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" :clearable="false" :editable="false" @blur="changeTime" @input="$forceUpdate()"
              :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="优先抢购时间" prop="dateFour" ref="refThree" :key="14">
            <el-date-picker v-model="form.dateFour" type="datetimerange" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              @change="activeChange" :clearable="false" @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="公开发行抢购时间" prop="dateFive" ref="refFour" :key="15">
            <el-date-picker v-model="form.dateFive" type="datetimerange" value-format="yyyy-MM-dd HH:mm"
              format="yyyy-MM-dd HH:mm" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
              @change="activeChange" :clearable="false" @input="$forceUpdate()" :style="{width: inputWidth}">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="优先抢购库存" prop="whiteIssueTotal" ref="refFive" :key="16">
            <el-input v-model="form.whiteIssueTotal" placeholder="请填写优先抢购真实库存数量" :style="{width: inputWidth}" />
          </el-form-item>
          <el-form-item label="优先抢购虚拟库存" prop="whiteIssueVirtual" ref="refFive" :key="17">
            <el-input v-model="form.whiteIssueVirtual" placeholder="请填写优先抢购虚拟库存数量" :style="{width: inputWidth}" />
          </el-form-item>
          <el-form-item label="公开抢购库存" prop="buyIssueTotal" ref="refSix" :key="18">
            <el-input v-model="form.buyIssueTotal" placeholder="请填写公开抢购真实库存数量" :style="{width: inputWidth}" />
          </el-form-item>
          <el-form-item label="公开抢购虚拟库存" prop="buyIssueVirtual" ref="refSix" :key="19">
            <el-input v-model="form.buyIssueVirtual" placeholder="请填写公开抢购虚拟库存数量" :style="{width: inputWidth}" />
          </el-form-item>
          <el-form-item label="每人限购" prop="issueLimit" ref="" :key="20">
            <el-input v-model="form.issueLimit" placeholder="请填写每人限购数量" :style="{width: inputWidth}" />
          </el-form-item>
        </div>
        <el-form-item label="购买赠送积分">
          <div class="flex">
            <el-checkbox v-model="checked" style="margin-right: 20px" @change="checkedCoCoChange">神椰CoCo</el-checkbox>
            <el-form-item label="" prop="givingNum" ref="" v-if="checked">
              <el-input v-model.number="form.givingNum" placeholder="请填写赠送数量" style="width: 300px;" />
            </el-form-item>
          </div>
          <div class="flex">
            <el-checkbox v-model="checkedTf" style="margin-right: 20px" @change="checkedTfChange">椰分</el-checkbox>
            <el-form-item label="" prop="givingNum" ref="" v-if="checkedTf">
              <el-input v-model.number="form.givingNum" placeholder="请填写赠送数量" style="width: 300px;" />
            </el-form-item>
          </div>
        </el-form-item>
        <el-form-item label="积分抵扣" prop="integralDiscountType" ref="" :key="20">
          <el-switch
            v-model="form.integralDiscountType"
            active-value="2"
            inactive-value="1"
            active-text="开启"
            inactive-text="关闭">
          </el-switch>
        </el-form-item>
        <template v-if="form.integralDiscountType == 2">
          <el-form-item label="积分类型" prop="integralType">
            <el-select filterable  v-model="form.integralType" placeholder="请选择" clearable
              size="small" :style="{width: inputWidth}">
              <el-option v-for="dict in integralTypeList" :key="dict.id" :label="dict.value" :value="dict.id" />
            </el-select>
          </el-form-item>
          <el-form-item label="可用数量" prop="integralUseAmount">
            <el-input v-model="form.integralUseAmount" placeholder="请输入积分可用数量" :style="{width: inputWidth}" />
          </el-form-item>
          <el-form-item label="抵扣金额" prop="integralDiscountMoney">
            <el-input v-model="form.integralDiscountMoney" placeholder="请输入积分可抵扣金额" :style="{width: inputWidth}" />
          </el-form-item>
        </template>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :loading="submitLoading" v-if="!disabled">发 布</el-button>
        <el-button @click="cancel" v-if="!disabled">取 消</el-button>
        <el-button @click="cancel" v-if="disabled">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getEquityCardIssue,
    addEquityCardIssue,
    updateEquityCardIssue,
    cardSelectLs,
  } from "@/api/equityManager/equityCardIssue";

  export default {
    // dicts: ['asset_card_type'],
    name: "Dialog",
    data() {
      var validateInventory= (rule, value, callback) => { 
        var reg = /(^[0-9]\d*$)/
        if (value === '') {
          callback(new Error('请填写库存数量'));
        } else if (!reg.test(value)) {
          callback(new Error('请填写正整数'));
        }  else {
          callback();
        }
      };
      var validateoneOdds = (rule, value, callback) => {
        var reg = /^([0-9]{1}|^[1-9]{1}\d{1,15})(\.\d{1,2})?$/
        if (value === '') {
          callback(new Error('请填写队1赔率'));
        } else if (value < 1) {
          callback(new Error('请填写大于1的数值'));
        } else if (!reg.test(value)) {
          callback(new Error('最多输入两位小数'));
        } else {
          callback();
        }
      };
      var validateIntegralUseAmount = (rule, value, callback) => {
        var reg = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
        if (!value) {
          callback(new Error('请输入积分可用数量'));
        } else if (!reg.test(value) && value) {
          callback(new Error('请输入大于等于0的数值，可保留两位小数')); 
        } else {
          callback()
        }
      };
      var validateIntegralDiscountMoney = (rule, value, callback) => {
        var reg = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
        if (!value) {
          callback(new Error('请输入积分可抵扣金额'));
        } else if (!reg.test(value) && value) {
          callback(new Error('请输入大于等于0的数值，可保留两位小数')); 
        } else {
          callback()
        }
      };
      return {
        labelWidth: '140px',
        inputWidth: '400px',
        id: '', //
        cardDisabled: false,
        submitLoading: false,
        checked: false, //购买赠送积分选择 true 选择  false 不选择
        checkedTf: false,//购买赠送椰分选择 true 选择  false 不选择
        // 是否禁用表单
        disabled: false,
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        visible: false,
        // 申购执行时间禁用
        purchaseDisable: true,
        // 付款截止时间禁用
        payDisable: true,
        // 发放权益卡时间禁用
        puchDisable: true,
        //上架权益卡数组
        cardOptin: [],
        //积分类型数组
        integralTypeList: [
          {id: '1', value: '神椰CoCo'},
          {id: '2', value: '椰分'},
        ],
        // 表单参数
        form: {
          equityCardId: '', //权益卡id
          issueType: '1', //发行方式（1 直接购买 2 预约申购）
          startTime: '', //开始时间（直接购买开始时间 或预约开始时间）	
          endTime: '', //结束时间（直接购买结束时间 或预约结束时间）
          executeTime: '', //申购执行时间
          issueTime: '', //发放权益卡时间
          payTime: '', //付款截止时间
          issueInventory: '', //发放库存
          issueInventoryVirtual:'',//发放虚拟库存
          buyIssueTotal: '', //公开抢购库存
          buyIssueVirtual:'',//公开抢购虚拟库存
          whiteIssueTotal: '', //优先抢购库存
          whiteIssueVirtual:'',//优先抢购虚拟库存
          whiteTime: '', //白名单公布时间
          whiteStartBuyTime: '', //优先抢购开始时间
          whiteEndBuyTime: '', //优先抢购结束时间
          startBuyTime: '', //公开发行抢购开始时间
          endBuyTime: '', //公开发行抢购结束时间
          issueLimit: '', //每人限购数量
          date: [],
          dateTwo: [],
          dateThree: [],
          dateFour: [],
          dateFive: [],
          subscribeEnable: '2', //是否启用预约功能 预约开关 1开启预约 2 关闭预约
          subscribeType: '1', //预约类型 1预约用户直接进入白名单 2预约用户抽取白名单资格 3预约用户没有特权
          givingType: '', //赠送积分类型 1 神椰CoCo  2: 椰分
          givingNum: '', //赠送积分数量
          integralDiscountType: '1',//积分抵扣类型 1 关闭 2开启
          integralType: '',//积分类型 1 神椰Coco 2椰分
          integralUseAmount: '',//积分使用数量
          integralDiscountMoney: '',//积分抵扣金额
        },
        // 表单校验
        rules: {
          equityCardId: [{
            required: true,
            message: "请选择上架权益卡",
            trigger: ["blur", "change"]
          }],
          issueType: [{
            required: true,
            message: "请选择发行方式",
            trigger: ["blur", "change"]
          }],
          date: [{
            required: true,
            message: "可购买时间",
            trigger: "change"
          }],
          dateTwo: [{
            required: true,
            message: "请选择可预约时间",
            trigger: "change"
          }],
          executeTime: [{
            required: true,
            message: "请选择申购执行时间",
            trigger: "change"
          }],
          payTime: [{
            required: true,
            message: "请选择付款截止时间",
            trigger: "change"
          }],
          issueTime: [{
            required: true,
            message: "请选择发放权益卡时间",
            trigger: "change"
          }],
          issueInventory: [{
            required: true,
            validator: validateInventory,
            trigger: ["blur", "change"]
          }],
          issueInventoryVirtual: [{
            required: true,
            message: "请填写虚拟库存数量",
            trigger: ["blur", "change"]
          }],
          dateThree: [{
            required: true,
            // type: 'array',
            message: "请选择公开发行预约时间",
            trigger: "change"
          }],
          whiteTime: [{
            required: true,
            message: "请选择白名单公布时间",
            trigger: "change"
          }],
          dateFour: [{
            required: true,
            message: "请选择优先抢购时间",
            trigger: "change"
          }],
          dateFive: [{
            required: true,
            message: "请选择公开发行抢购时间",
            trigger: "change"
          }],
          whiteIssueTotal: [{
            required: true,
            // message: "请填写优先抢购真实库存数量",
            validator: validateInventory,
            trigger: ["blur", "change"]
          }],
          whiteIssueVirtual: [{
            required: true,
            // message: "请填写优先抢购虚拟库存数量",
            validator: validateInventory,
            trigger: ["blur", "change"]
          }],
          buyIssueTotal: [{
            required: true,
            // message: "请填写公开抢购真实库存数量",
            validator: validateInventory,
            trigger: ["blur", "change"]
          }],
          buyIssueVirtual: [{
            required: true,
            // message: "请填写公开抢购虚拟库存数量",
            validator: validateInventory,
            trigger: ["blur", "change"]
          }],
          issueLimit: [{
            required: true,
            message: "请填写每人限购数量",
            trigger: ["blur", "change"]
          }],
          givingNum: [{
            required: true,
            message: "请填写赠送数量",
            trigger: ["blur", "change"]
          }],
          integralDiscountType: [{
            required: false,
            message: "请选择",
            trigger: "change"
          }],
          integralUseAmount: [{
            required: true,
            validator: validateIntegralUseAmount,
            trigger: ["blur", "change"]
          }],
          integralDiscountMoney: [{
            required: true,
            validator: validateIntegralDiscountMoney,
            trigger: ["blur", "change"]
          }],
        },
        end_Date: this.endDate(),
        end_Date_Two: this.endDateTwo(),
        end_Date_Three: this.endDateThree(),
      };
    },
    created() {

    },
    methods: {
      //获取数字权益卡选择列表
      getCardSelectLs(id) {
        let data = {
          cardName: '',
          cardId: id,
        }
        cardSelectLs(data).then(response => {
          this.cardOptin = response.result
        });
      },
      /** 打开发行管理弹框 */
      open(id, disabled, cardId) {
        this.getCardSelectLs(cardId)
        this.reset();
        this.disabled = disabled
        this.id = id
        if (id) {
          this.cardDisabled = true
          getEquityCardIssue(id).then(response => {
            // this.form = response.result;
            this.form = {
              id: response.result.id,
              equityCardId: response.result.equityCardId, //权益卡id
              issueType: response.result.issueType, //发行方式（1 直接购买 2 预约申购）
              startTime: response.result.startTime, //开始时间（直接购买开始时间 或预约开始时间）	
              endTime: response.result.endTime, //结束时间（直接购买结束时间 或预约结束时间）
              executeTime: response.result.executeTime, //申购执行时间
              issueTime: response.result.issueTime, //发放权益卡时间
              payTime: response.result.payTime, //付款截止时间
              issueInventory: response.result.issueInventory, //发放库存
              issueInventoryVirtual: response.result.issueInventoryVirtual,//发放虚拟库存
              buyIssueTotal: response.result.buyIssueTotal, //公开抢购库存
              buyIssueVirtual: response.result.buyIssueVirtual,//公开抢购虚拟库存
              whiteIssueTotal: response.result.whiteIssueTotal, //优先抢购真实库存
              whiteIssueVirtual: response.result.whiteIssueVirtual, //优先抢购虚拟库存
              whiteTime: response.result.whiteTime, //白名单公布时间
              whiteStartBuyTime: response.result.whiteStartBuyTime, //优先抢购开始时间
              whiteEndBuyTime: response.result.whiteEndBuyTime, //优先抢购结束时间
              startBuyTime: response.result.startBuyTime, //公开发行抢购开始时间
              endBuyTime: response.result.endBuyTime, //公开发行抢购结束时间
              issueLimit: response.result.issueLimit, //每人限购数量
              date: [],
              dateTwo: [],
              dateThree: [],
              dateFour: [],
              dateFive: [],
              integralDiscountType: response.result.integralDiscountType,
              integralType: response.result.integralType,
              integralUseAmount: response.result.integralUseAmount,
              integralDiscountMoney: response.result.integralDiscountMoney,
              subscribeEnable: response.result.subscribeEnable, //是否启用预约功能 预约开关 1开启预约 2 关闭预约
              subscribeType: response.result.subscribeType, //预约类型 1预约用户直接进入白名单 2预约用户抽取白名单资格 3预约用户没有特权
              givingType: response.result.givingType, //赠送积分类型 1 神椰coco 2椰分
              givingNum: response.result.givingNum, //赠送积分数量
            }
            this.form.cover = response.result.cover
            this.form.price = response.result.price
            this.form.issueTotal = response.result.issueTotal
            if (response.result.issueType == 1) {
              this.form.date = []
              this.form.date[0] = response.result.startTime
              this.form.date[1] = response.result.endTime
            } else if (response.result.issueType == 2) {
              this.form.dateTwo = []
              this.form.dateTwo[0] = response.result.startTime
              this.form.dateTwo[1] = response.result.endTime
            } else {
              if (this.form.subscribeEnable == '2') {
                this.form.subscribeType = '1'
              }
              this.form.dateThree = []
              this.form.dateThree[0] = response.result.startTime
              this.form.dateThree[1] = response.result.endTime
              this.form.dateFour = []
              this.form.dateFour[0] = response.result.whiteStartBuyTime
              this.form.dateFour[1] = response.result.whiteEndBuyTime
              this.form.dateFive = []
              this.form.dateFive[0] = response.result.startBuyTime
              this.form.dateFive[1] = response.result.endBuyTime
            }
            //处理是否选择神椰积分或者椰分
            if (this.form.givingType == '1') {
              this.checked = true
              this.checkedTf = false
              // this.$set(this.form,'checked',true) //用this.$set修复无法选择问题
            } else if(this.form.givingType == '2') {
              this.checked = false
              this.checkedTf = true
              // this.$set(this.form,'checked',false) //用this.$set修复无法选择问题
            }
            console.log(this.form)
          });
        }
        this.visible = true
        if (this.disabled) {
          this.title = "配置发布方式"
        } else if (id) {
          this.title = "编辑发布方式"
        } else {
          this.title = "配置发布方式"
        }
      },
      // 取消按钮
      cancel() {
        this.visible = false;
        this.reset();
      },
      radioChange(e) {
        console.log(e)
        // if (this.form.issueType == '1') {
        //   this.$refs['refOne'].clearValidate();
        //   this.$refs['refTwo'].clearValidate();
        //   this.$refs['refThree'].clearValidate();
        // } else if (this.form.issueType == '2') {
        //   this.$refs['refOne'].clearValidate();
        //   this.$refs['refTwo'].clearValidate();
        //   this.$refs['refThree'].clearValidate();
        //   this.$refs['refFour'].clearValidate();
        //   this.$refs['refFive'].clearValidate();
        // } else {
        //   if (this.form.subscribeEnable == '1') {
        //     this.$refs['refOne'].clearValidate();
        //     this.$refs['refEight'].clearValidate();
        //   }
        //   this.$refs['refTwo'].clearValidate();
        //   this.$refs['refThree'].clearValidate();
        //   this.$refs['refFour'].clearValidate();
        //   this.$refs['refFive'].clearValidate();
        //   this.$refs['refSix'].clearValidate();
        //   this.$refs['refSeven'].clearValidate();
        // }

      },
      checkedCoCoChange(e){ //coco选择
        console.log('积分',e)
        if(e==true){
          this.form.givingType = '1'
          this.checkedTf = false
        }else{
          this.form.givingType = ''
        }
        console.log(this.form.givingType)
      },
      checkedTfChange(e){ //椰分选择
        console.log('椰分',e)
        if(e==true){
          this.form.givingType = '2'
          this.checked = false
        }else{
          this.form.givingType = ''
        }
        console.log(this.form.givingType)
      },
      dateThreeChange(e) {
        console.log(e)
      },
      changeBuy(e) { //可购买时间选择
        console.log(this.form.date)
        if (this.form.date != undefined) {
          this.form.startTime = this.form.date[0]
          this.form.endTime = this.form.date[1]
          // this.purchaseDisable = false
          // this.form.executeTime = ''
          this.$forceUpdate()
        }
      },
      //可预约时间选择
      activeChange(e) {
        console.log(this.form.dateTwo)
        if (this.form.dateTwo != undefined) {
          this.form.startTime = this.form.dateTwo[0]
          this.form.endTime = this.form.dateTwo[1]
          this.purchaseDisable = false
          this.form.executeTime = ''
          this.$forceUpdate()
        }
        this.$forceUpdate()
      },
      endDate() { //控制申购执行时间选择disable
        let that = this
        return {
          disabledDate(time) {
            return time.getTime() <= new Date(that.form.endTime).getTime();
          }
        }
      },
      //申购执行时间
      changeTime(e) {
        console.log(this.form.executeTime)
        if (this.form.executeTime != undefined && this.form.executeTime != '') {
          this.payDisable = false
          this.form.payTime = ''
          this.$forceUpdate()
        }
      },
      endDateTwo() { //控制付款截止时间选择disable
        let that = this
        return {
          disabledDate(time) {
            return time.getTime() <= new Date(that.form.executeTime).getTime();
          }
        }
      },
      changePayTime(e) {
        console.log(this.form.payTime)
        if (this.form.payTime != undefined && this.form.payTime != '') {
          this.puchDisable = false
          this.form.issueTime = ''
          this.$forceUpdate()
        }
      },
      endDateThree() { //控制发放权益卡时间选择disable
        let that = this
        return {
          disabledDate(time) {
            return time.getTime() <= new Date(that.form.payTime).getTime();
          }
        }
      },
      // 表单重置
      reset() {
        // 子表选中数据
        this.cardDisabled = false
        this.checked = false //购买赠送积分选择 true 选择  false 不选择
        this.form = {
          equityCardId: '', //权益卡id
          issueType: '1', //发行方式（1 直接购买 2 预约申购）
          startTime: '', //开始时间（直接购买开始时间 或预约开始时间）	
          endTime: '', //结束时间（直接购买结束时间 或预约结束时间）
          executeTime: '', //申购执行时间
          issueTime: '', //发放权益卡时间
          payTime: '', //付款截止时间
          issueInventory: '', //发放库存
          issueInventoryVirtual:'',//发放虚拟库存
          buyIssueTotal: '', //公开抢购库存
          buyIssueVirtual:'',//公开抢购虚拟库存
          whiteIssueTotal: '', //优先抢购库存
          whiteIssueVirtual: '', //优先抢购虚拟库存
          whiteTime: '', //白名单公布时间
          whiteStartBuyTime: '', //优先抢购开始时间
          whiteEndBuyTime: '', //优先抢购结束时间
          startBuyTime: '', //公开发行抢购开始时间
          endBuyTime: '', //公开发行抢购结束时间
          date: [],
          dateTwo: [],
          dateThree: [],
          dateFour: [],
          dateFive: [],
          subscribeEnable: '2', //是否启用预约功能 预约开关 1开启预约 2 关闭预约
          subscribeType: '1', //预约类型 1预约用户直接进入白名单 2预约用户抽取白名单资格 3预约用户没有特权
          givingType: '', //赠送积分类型 1 神椰coin 2椰分
          givingNum: '', //赠送积分数量
        }
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.submitLoading = true
            if (this.form.issueType == '1') { //直接购买
              this.form.startTime = this.form.date[0]
              this.form.endTime = this.form.date[1]
            } else if (this.form.issueType == '2') { //预约购买
              this.form.startTime = this.form.dateTwo[0]
              this.form.endTime = this.form.dateTwo[1]
            } else { //预约抢购
              // if (this.form.dateThree != undefined) {
              //   this.form.startTime = this.form.dateThree[0]
              //   this.form.endTime = this.form.dateThree[1]
              // }
              this.form.startTime = this.form.dateThree[0]
              this.form.endTime = this.form.dateThree[1]
              this.form.whiteStartBuyTime = this.form.dateFour[0]
              this.form.whiteEndBuyTime = this.form.dateFour[1]
              this.form.startBuyTime = this.form.dateFive[0]
              this.form.endBuyTime = this.form.dateFive[1]
            }
            // 打开遮罩层
            // this.$modal.loading("正在处理中数据，请稍后...");
            if (this.form.id != null) {
              updateEquityCardIssue(this.form).then(response => {
                this.$message.success('修改成功');
                this.cancel();
                this.$emit('refresh')
                this.submitLoading = false
              }).catch(() => {
                this.submitLoading = false
              });
            } else {
              addEquityCardIssue(this.form).then(response => {
                this.$message.success('新增成功');
                this.cancel();
                this.$emit('refresh')
                this.submitLoading = false
              }).catch(() => {
                this.submitLoading = false
              });
            }
          }
        });
      },
      /** 序号 */
      rowIndex({
        row,
        rowIndex
      }) {
        row.index = rowIndex + 1;
      },
      /** 添加按钮操作 */
      handleAdd() {
        let obj = {};
        this.List.push(obj);
      },
      /** 删除按钮操作 */
      handleDelete() {
        if (this.checked.length == 0) {
          this.$modal.msgError("请先选择要删除的数据");
        } else {
          const List = this.List;
          const checked = this.checked;
          this.List = List.filter(function (item) {
            return checked.indexOf(item.index) == -1;
          });
        }
      },
      /** 复选框选中数据 */
      handleSelectionChange(selection) {
        this.checked = selection.map(item => item.index)
      },
    }
  };

</script>
<style scoped>
  .img_box {
    width: 100px;
    height: 70px;
    border-radius: 4px;
  }

  .flex {
    display: flex;
  }

</style>
